public class Demo10 {
    //在t线程中计算1+2+3+...+1000,在主线程中打印结果
    private static long result=0;
    public static void main(String[] args) throws InterruptedException {
        Thread t=new Thread(()->{
            for (int i = 1; i <=1000; i++) {
                result+=i;
            }
            System.out.println("t线程计算完毕");
        });
        t.start();
        t.join(); //让main线程去等待t线程，等到t线程退出，join才会返回，主线程才会继续执行
        System.out.println(result);
    }
}
